def quik2(L):
    end_index = len(L)
    temp_index = end_index/2 - 1 
    temp = L[temp_index]
    left_tag = 0
    right_tag = 0
    x= 0
    for i1 in range(0,end_index): 
        i = i1 + x
        if L[i] < temp:
            arryLi = L
            if i > temp_index:            
                L = mv(temp_index, i, arryLi)
                print temp_index,'a1',L[i],L
                temp_index = temp_index + 1
                left_tag = left_tag + 1
                print 'left_tag is ',left_tag
            else:
                print temp_index,'a2',L[i],L
                left_tag = left_tag + 1
                print 'left_tag is ',left_tag
        elif L[i] > temp:
            arryLi = L
            if i < temp_index:
                L = mv2(i, temp_index, arryLi)
                print temp_index,'b1',L[i],L
                temp_index = temp_index - 1                
                right_tag = right_tag + 1
                x = x - 1
                end_index = end_index + 1
                print 'right_tag is ',right_tag
            else:
                print temp_index,'b2',L[i],L
                right_tag = right_tag + 1
                print 'right_tag is ',right_tag
        else:
            if i > temp_index:
                print temp_index,'i>temp_index'
                right_tag = right_tag + 1
                print 'right_tag is ',right_tag
            elif i < temp_index:
                print temp_index,'i<temp_index'
                left_tag = left_tag + 1
                print 'left_tag is ',left_tag
            else:
                print 'tongyige======='
                
    print 'temp_index is ',temp_index,'left_tag is ',left_tag,'right_tag is ',right_tag
    if left_tag > 1:
        array_digui_left = L[temp_index-left_tag:temp_index]
        L[temp_index-left_tag:temp_index] = quik2(array_digui_left)
    if right_tag > 1:
        array_digui_right = L[temp_index+1:temp_index+1+right_tag]
        L[temp_index+1:temp_index+1+right_tag] = quik2(array_digui_right)
    print L
    return L

def mv(star_targ,end_targ,Li):
    z = Li[end_targ]
    for i in range(star_targ, end_targ):
        Li[end_targ] = Li[end_targ-1]
        end_targ = end_targ -1
    Li[star_targ] = z
    return Li

def mv2(star_targ,end_targ,Li):
    z = Li[star_targ]
    s = end_targ
    for i in range(star_targ, end_targ):
        Li[i] = Li[i+1]
        end_targ = end_targ - 1
    Li[s] = z
    return Li

print quik2([9,9,32,5,1,8,23,0,3,2,9,7,7,10,45])